var app = getApp()
import {
  clickAndGet
} from '../../api/promotion'
import util from '../../utils/util'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    promotionForm: {
      type: Object,
      value: '',
    },
    promotionPrice: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isMaskType: false,
    successType: false
  },
  pageLifetimes: {
    
    show: function () {
      var _this = this
      if(util.isNull(!_this.data.promotionForm)){
        wx.getStorage({
          key: 'todayTime',
          success(res) {
            var nowDate = new Date();
            var nowTime = nowDate.toLocaleDateString().split('/').join('-');
            if (!util.isNull(res.data) && (nowTime == res.data)) {
              _this.data.isMaskType = false
            } else {
              _this.data.isMaskType = true
              wx.removeStorage({
                key: 'todayTime',
                success(res) {
                }
              })
            }
          },fail(error){
            _this.data.isMaskType = true
          }
        })
      }else{
        _this.data.isMaskType = false
      }
      _this.setData({
        isMaskType: _this.data.isMaskType
      })
      
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    closeClick() {
      var myDate = new Date();
      var time = myDate.toLocaleDateString().split('/').join('-');
      wx.setStorage({
        key: "todayTime",
        data: time
      })
      this.data.isMaskType = false
      this.data.successType = false
      this.setData({
        isMaskType: this.data.isMaskType,
        successType: this.data.successType
      })
    },
    successClick() {
      var _this = this
      if (app.globalData.token == null) {
        wx.navigateTo({
          url: '/pages/login/index',
        })
        return;
      }
      // 弹屏领取
      clickAndGet({
        promotionId: _this.data.promotionForm.promotion.id
      }).then(res => {
        console.log(res)
        this.data.successType = true
        this.setData({
          successType: this.data.successType
        })
      })
    },
    couponClick() {
      // this.data.isMaskType = true
      // this.setData({
      //   isMaskType: this.data.isMaskType
      // })
    },
    seeClick() {
      var _this = this
      wx.navigateTo({
        url: '/pages/member/coupon/index',
        success: function (res) {
          _this.data.isMaskType = false
          _this.setData({
            isMaskType: _this.data.isMaskType
          })
        }
      })
    },
    useClick() {
      this.data.isMaskType = false
      this.data.successType = false
      this.setData({
        successType: this.data.successType,
        isMaskType: this.data.isMaskType
      })
    }
  }
})